<template>
	<view class="goods_list">
		<goods-list @goodsItemClick="goGoodsDetail" :goods="goods"></goods-list>
		<view class="isOver" v-if="flag">-----我是有底线的-----</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				pageIndex: 1,
				goods: [{
						image: '../../static/shangpin/huawei6.jpg',
						price: 2199,
						price_yuan: 2499,
						name: '华为荣耀 6plus'
					},
					{
						image: '../../static/shangpin/huawei6.jpg',
						price: 2199,
						price_yuan: 2499,
						name: '华为荣耀 6plus'
					},
					{
						image: '../../static/shangpin/huawei6.jpg',
						price: 2199,
						price_yuan: 2499,
						name: '华为荣耀 6plus'
					},
					{
						image: '../../static/shangpin/huawei6.jpg',
						price: 2199,
						price_yuan: 2499,
						name: '华为荣耀 6plus'
					}, {
						image: '../../static/shangpin/huawei6.jpg',
						price: 2199,
						price_yuan: 2499,
						name: '华为荣耀 6plus'
					}, {
						image: '../../static/shangpin/huawei6.jpg',
						price: 2199,
						price_yuan: 2499,
						name: '华为荣耀 6plus'
					}
				],
				flag: false
			}
		},
		onLoad() {
			//this.getGoodsList()
		},
		components: {
			"goods-list": goodsList
		},
		methods: {
			async getGoodsList(callBack) {
				const res = await this.$myRequest({
					url: '' + this.pageIndex
				})
				//保留原有数据
				this.goods = [...this.goods, ...res.data.message]
				//有就调用 
				callBack && callBack()
			},
			goGoodsDetail(index){
				uni.navigateTo({
					url: '/pages/goods-detail/goods-detail?id='+index
				})
			}
		},
		//触底触发事件
		onReachBottom() {
			//因返回数据无总数
			if (this.goods.length < this.pageIndex * 10) return this.flag = true
			this.pageIndex++;
			//this.getGoodsList()
		},
		//下拉刷新触发事件
		onPullDownRefresh() {
			this.pageIndex = 1
			this.goods = []
			this.flag = false
			uni.stopPullDownRefresh()
			/* setTimeout(()=>{
				this.getGoodsList(()=>{
					uni.stopPullDownRefresh()
				})
			},1000) */

		}
	}
</script>

<style lang="scss">
	.goods_list {
		background-color: #eee;
	}

	.isOver {
		width: 100%;
		height: 50px;
		line-height: 50px;
		text-align: center;
		font-size: 28rpx;
	}
</style>
